package org.wangnian;

import org.wangnian.service.IFanCoreService;

import java.util.Iterator;
import java.util.ServiceLoader;

public class Main {

    public static final String A_TYPE = "A";

    public static void main(String[] args) {
        turnOn(A_TYPE);
    }

    public static void turnOn(String type){
        //通过ServiceLoader类的load方法去发现服务提供者并加载
        ServiceLoader<IFanCoreService> loader = ServiceLoader.load(IFanCoreService.class);
        Iterator<IFanCoreService> iterator = loader.iterator();

        while (iterator.hasNext()){
            IFanCoreService iFanCoreService = iterator.next();
            System.out.println("检测到的类名：" + iFanCoreService.getClass().getName() + ":" +iFanCoreService);
            //判断是否是A型号的风扇，是的话直接开启
            if (A_TYPE.equals(iFanCoreService.getType())){
                iFanCoreService.turnOnOff();
            }
        }
    }

}
